export default class Enum {
  _arr = null
  _json = null

  // 构造函数是字典数据
  constructor(key, data) {
    this._arr = data
    this._json = this.getJsonData(key)
  }
  get arrData() {
    return this._arr
  }
  get jsonData() {
    return this._json
  }
  /**
   * 根据key，获取json格式的字典数据
   * @function
   * @param {*} key - json字典的key值
   * @return {Object} 返回json类型的字典数据
   */
  getJsonData(key) {
    let obj = {}
    this._arr.forEach((item) => {
      const tkey = item[key]
      if (tkey) {
        obj[tkey] = item
      }
    })
    return obj
  }
}
